package com.sibu.yx.promotion.admin.web;

import com.sibu.yx.promotion.persistence.config.AppConfig;
import lombok.extern.slf4j.Slf4j;

import org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.Arrays;


/**
 * @author yuwenbo
 * @create 2019-04-01 16:37
 **/
@Slf4j
@SpringBootApplication(
        scanBasePackages =
                {"com.sibu.yx.promotion.service",
                        "com.sibu.yx.promotion.persistence",
                        "com.sibu.yx.promotion.admin.web.support",},
        exclude = {DataSourceAutoConfiguration.class, SpringBootConfiguration.class})
public class AdminWebApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication springApplication=new SpringApplication(AdminWebApplication.class);
        springApplication.setBannerMode(Banner.Mode.CONSOLE);
        ConfigurableApplicationContext ctx =springApplication.run(args);
        if ("true".equalsIgnoreCase(ctx.getEnvironment().getProperty("debug"))) {
            StringBuilder allBeanNameStr = new StringBuilder(500);
            allBeanNameStr.append("----------------- spring beans ------------------------\n");
            String[] beanNames = ctx.getBeanDefinitionNames();
            allBeanNameStr.append("beanNames 总数：" + beanNames.length + "\n");
            Arrays.sort(beanNames);
            for (String bn : beanNames) {
                allBeanNameStr.append(bn + "\n");
            }
            allBeanNameStr.append("------------------ end -----------------------");
            System.out.println(allBeanNameStr.toString());
            log.info("当前环境为:{}", AppConfig.getInstance().getEnvironmentName());
        }
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        log.info("init SpringApplicationBuilder ...");
        return application.sources(AdminWebApplication.class);
    }
}
